<?
class Tbl_kontenstatis extends CI_Model {
    var $tabel;

	//================ADMIN==================//
     function __construct(){
         // Call the Model constructor
         parent::__construct();
		$this->tabel ="tbl_kontenstatis";
	}
	//------------Main Function
	
	
	function edit($id) {
      $query=$this->db->query("SELECT * FROM ".$this->tabel." WHERE id='$id'");
      return $query->result();
	 }
	
	function update($id, $isi, $tanggal) {
		$this->db->query("UPDATE ".$this->tabel." SET 
							isi		='$isi', 
							tanggal	='$tanggal'
							WHERE id=$id ");
    }
	
	//------------Function
	
	function load() {
	$posisi = $this->uri->segment(3);
    if(!is_numeric($posisi))
    {
      $posisi='0';
      $query=$this->db->query("SELECT * FROM ".$this->tabel." ORDER BY id ASC LIMIT $posisi,10");
      return $query->result();
    }
	if(empty($posisi)) {$posisi = '0';}
  
		$query=$this->db->query("SELECT * FROM ".$this->tabel." ORDER BY id DESC LIMIT $posisi,10");
		return $query->result();
	 }
	
	function hitung(){
		$data = $this->db->query("SELECT * FROM ".$this->tabel);
		$banyak= $this->db->affected_rows($data);
		return $banyak;
	}
	
	function viewContentStatic($id){
		$this->db->from($this->tabel);
		$this->db->where('id', $id);
        $query = $this->db->get();
		return $query->row();
	}
	
	function searchKontenStatisGuest($key){
		$query = $this->db->query("SELECT *, DATE_FORMAT(tanggal, '%e %M %Y, %l:%i%p') as newdate FROM ".$this->tabel." WHERE status='publish' AND (judul RLIKE '$key' OR isi RLIKE '$key' OR penulis RLIKE '$key')");
		return $query->result();
	}
	
}
?>